package io.renren.modules.generator.controller;

import io.renren.common.exception.RRException;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.generator.entity.ContactsPeopleEntity;
import io.renren.modules.generator.entity.WebUrl;
import io.renren.modules.generator.service.ContactsPeopleService;
import io.renren.modules.generator.service.MissPeopleService;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * @author guijing
 * @email sunlightcs@gmail.com
 * @date 2022-01-31 16:10:18
 */
@RestController
@RequestMapping("web/misspeople")
public class WebGetController {

    @Autowired
    private MissPeopleService missPeopleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = missPeopleService.queryPageByWeb(params);

        return R.ok().put("page", page);
    }


    @RequestMapping("/newMiss")
    @Transactional
    public R newMiss() {
        missPeopleService.autoGetNewMissPeople();
        return R.ok();
    }


    /**
     * 保存
     */
    @RequestMapping("/save")
    @Transactional
    public R save(@RequestBody WebUrl webUrl) {
        String url = webUrl.getUrl();
        try {
            if(StringUtils.isNotBlank(url)) {
                missPeopleService.saveMissPeople(url);
            }
        } catch (Exception e) {
            throw new RRException("文件路径连接失败,请稍后再试");
        }
        return R.ok();
    }


}
